package cn.cms.webcommon;

import org.springframework.context.ApplicationContext;

public class LocalContextFactory
        implements Factory {
    private ApplicationContext springWebContext;
    private static LocalContextFactory instance = new LocalContextFactory();

    public Object getBean(String name) {
        if (this.springWebContext == null) {
            throw new RuntimeException("springWebContext is null!!!!!");
        }
        return this.springWebContext.getBean(name);
    }

    public static LocalContextFactory getInstance() {
        return instance;
    }

    public void setSpringWebContext(ApplicationContext springWebContext) {
        this.springWebContext = springWebContext;
    }

    public ApplicationContext getSpringWebContext() {
        return this.springWebContext;
    }

    public <T> T getBean(String name, Class<T> requiredType) {
        return this.springWebContext.getBean(name, requiredType);
    }

    public <T> T getBean(Class<T> requiredType) {
        return this.springWebContext.getBean(requiredType);
    }

}
